package com.codename1.samples;


import com.codename1.components.ToastBar;
import static com.codename1.ui.CN.*;
import com.codename1.ui.Display;
import com.codename1.ui.Form;
import com.codename1.ui.Dialog;
import com.codename1.ui.Label;
import com.codename1.ui.plaf.UIManager;
import com.codename1.ui.util.Resources;
import com.codename1.io.Log;
import com.codename1.ui.Toolbar;
import java.io.IOException;
import com.codename1.ui.layouts.BoxLayout;
import com.codename1.io.NetworkEvent;
import com.codename1.ui.Button;
import com.codename1.ui.TextField;

/**
 * This file was generated by <a href="https://www.codenameone.com/">Codename One</a> for the purpose 
 * of building native mobile applications using Java.
 */
public class IOS13RegressionTest {

    private Form current;
    private Resources theme;

    public void init(Object context) {
        // use two network threads instead of one
        updateNetworkThreadCount(2);

        theme = UIManager.initFirstTheme("/theme");

        // Enable Toolbar on all Forms by default
        Toolbar.setGlobalToolbar(true);

        // Pro only feature
        Log.bindCrashProtection(true);

        addNetworkErrorListener(err -> {
            // prevent the event from propagating
            err.consume();
            if(err.getError() != null) {
                Log.e(err.getError());
            }
            Log.sendLogAsync();
            Dialog.show("Connection Error", "There was a networking error in the connection to " + err.getConnectionRequest().getUrl(), "OK", null);
        });        
    }
    
    public void start() {
        if(current != null){
            current.show();
            return;
        }
        
        new Form1().show();
    }

    class Form1 extends Form {
        public Form1() {
            Toolbar tb = new Toolbar();
            setToolbar(tb);
            tb.addCommandToLeftSideMenu("Form 2", null, ev->{
                new Form2().show();
            });
            
            setTitle("Form 1");
            TextField tf = new TextField();
            tf.setHint("Hint text");
            tf.getHintLabel().getAllStyles().setFgColor(0xff0000);
            add(tf);
            
            Button b = new Button("Test Button");
            b.addActionListener(evt->{
                ToastBar.showInfoMessage("Button worked");
            });
            add(b);
            TextField tf2 = new TextField();
            add(tf2);
            
        }
    }
    
    class Form2 extends Form {
        public Form2() {
            Toolbar tb = new Toolbar();
            setToolbar(tb);
            tb.addCommandToLeftSideMenu("Form 1", null, ev->{
                new Form1().show();
            });
            
            setTitle("Form 2");
            add(new TextField());
            
        }
    }
    
    public void stop() {
        current = getCurrentForm();
        if(current instanceof Dialog) {
            ((Dialog)current).dispose();
            current = getCurrentForm();
        }
    }
    
    public void destroy() {
    }

}
